from dingtalk_service.yida_client_base import YidaClientBase

'''linanzjz 临安质监站'''

class YidaClient(YidaClientBase):
    # 从宜搭应用获取
    system_token = '9Z766DC13QYNPSOA63GV6DOFGG9020QYTKA0MHVE'
    app_type = 'APP_Z006W6F6CE9REPXVWPH6'
    base_url = "https://qlbdew.aliwork.com"
    # 从钉钉应用获取
    app_key = "dingcpz9spcoiebyoyqq"
    app_secret = "CXtCphO37-6IwKWUofzBADMoGGnD2hrTx4_6YK9Lh6MyZ_LK3xym31dssi5xIuJd"
    admin_user_id = "014835331124251186"

    # 自定义数据库相关信息配置
    is_custom = True

    # 同步工程配置 sysProjectInfomationLib
    project_form_uuid = "FORM-BD41952201D4490A804B013A18E98A5CQYKA"
    project_num_component_id = "textField_m1nbexlw"
    # 建研数据库同步到宜搭字段映射 !注意大小写
    project_sync_mapping = {
        "projectNum": "textField_m1nbexlw",  # 项目编号
        "projectName": "textField_lzrzlfjr", # 项目名称
        "CreateDate": "dateField_lzrzlfjq" , # 登记时间
        # "CreateMan": "employeeField_lzxw8qhj", # 项目受理人 # 暂时抛弃
        # "projectArea": "addressField_lzxvw0f0", # 项目地区 @由地区代码决定即可
        "ProjectKey": "textField_lzxvw0f1", # 地区代码
        "projectAddress": "textareaField_lzxvw0ez", # 项目地址
        # 委托
        "entrustUnit": "textField_lzrzlfk6", # 委托单位名称
        "sendSampleMan": "textField_lzrzlfkb", # 委托单位联系人
        "sendSampleManTel": "textField_lzrzlfkf", # 委托单位联系方式
        # 建设
        "constractUnit": "textField_lzrzlfk7", # 建设单位名称
        "constractUnitMan": "textField_lzrzlfkc", # 建设单位联系人
        "constractUnitManTel": "textField_lzrzlfkg", # 建设单位联系方式
        # 施工
        "constractionUnit": "textField_lzrzlfk8", # 施工单位名称
        "constractionUnitMan": "textField_lzrzlfkd", # 施工单位联系人
        "constractionUnitManTel": "textField_lzrzlfkh", # 施工单位联系方式
        # 监理 witness
        "witnessUnit": "textField_lzxw8qhi", # 监理单位名称
        "witnessMan": "textField_lzrzlfke", # 监理单位联系人
        "witnessManTel": "textField_lzrzlfki", # 监理单位联系方式

        # db无关字段 前缀default表示固定默认值处理
        "default_source": "textField_m1od7soo", # 项目来源 
        "default_status":"textField_m1od7sop" # 项目同步状态字段
    }

    default_project_config = {
        "default_source": "湖南建研",
        "default_status":"同步中"
    }

    # 同步委托配置 sysCurrentRecord
    current_record_form_uuid = "FORM-38C305CFD3D14A8B99984C59FE48E537J8SW"
    current_record_primary_key_component_id = "textField_lzs0x0b9"
    # 委托字段映射 !注意大小写
    current_record_sync_mapping = {
        "EntrustNum": "textField_lzs0x0b9", # 委托编号
        # "ProjectNum": "textField_m0am6qv4", # 项目编号
        # "ProjectName": "textField_lzuvzaex" , # 项目名称
        "ProjectNum": "associationFormField_lzs0x0am", # 选择项目编号关联表单 key用来判断关联表单是否有这条记录，未必用来填充该关联表单的值的，可以查看title_field_name属性
        "EntrustUnit": "textField_lzs0x0ba", # 委托单位
        "SendSampleMan": "textField_lzxv9z4b", # 委托人
        "SendSampleManTel": "textField_lzxv9z4c", # 委托人联系方式
        "EntrustDate": "dateField_lzweua3h", # 委托日期
        "&EntrustDate": "dateField_lzs0x0an", # 受理日期 '&+value值'表示使用某个key对应的value的值，但不进行反向同步

        # db无关字段
        "default_source": "textField_m1od59ce", # 委托来源
        "default_status": "textField_m1od59cf" # 同步状态
    }

    current_record_file = '/root/xm-detection-service/current_record.log'

    default_current_record_config = default_project_config

    #样品表同步字段
    sample_form_uuid = "FORM-2031FFBD99D1442AA606BB665B218400TTVG"
    sample_record_primary_key_component_id = "textField_lzwdkwlk"
    sample_sync_mapping = {
        # 项目信息
        "ProjectName": "associationFormField_lzuvjinv", # 项目名称
        "EntrustNum": "textField_lzwdkwlk" , # 委托编号
        "SampleNum": "textField_m0g5ssx7", # 样品编号
        # "organizerID": "employeeField_lzwdkwlm", # 编制人
        # # 试验信息
        "ItemName": "selectField_m0dj9ha3", # 检测项目
        "subitemlist":"tableField_m0emrkj5", # 检测参数
        # "markNum":"selectField_m0ngvnqd", # 牌号
        # "customSpec":"numberField_m0lqa7kr", # 自定义规格
        # "spec":"selectField_m0emrkj1", # 规格

        # db无关字段
        "default_source": "textField_m1od7soo", # 项目来源
        "default_itemQualification": "selectField_m0emrkj8", # 检测资质
        "default_itemTypes": "selectField_m0dj9ha7", # 检测大类
        "default_sample_group_num": "numberField_lzuzy7z5", # 样品组数
        "default_sample_order": "numberField_m0g5ssx9", # 样品序号
    }

    default_sample_config = {
        "default_itemQualification": "建筑结构及构配件", # 检测资质
        "default_itemTypes": "建研大类", # 检测大类
        "default_sample_group_num": 1, # 样品组数
        "default_sample_order": 1 # 样品序号
    }

    default_config = {**default_project_config,**default_current_record_config,**default_sample_config}

    table_config = {
        # 检测参数table配置
        "tableField_m0emrkj5":{
            "table_fields":{
                "name": "textField_m0emrkj4", # 检测参数名字
                "uid": "textField_m0emrkjb", # uid
                "single_cost": "numberField_m0emrkj7", # 单价
                "pointcount": "numberField_m0emrkj6" # 点数
            },
            "cost":"numberField_m0dj9ha5" # 检测项目-参数本组的的费用
        } 
    }

    # 联合表单字段配置
    association_config = {
        # 项目编号字段关联表单
        "associationFormField_lzs0x0am":{
            # 被关联表单配置信息
            "appType": 'APP_Z006W6F6CE9REPXVWPH6',
            "formType": 'receipt',
            "formUuid": 'FORM-BD41952201D4490A804B013A18E98A5CQYKA',
            # 正向同步配置
            # 查找关联的表的配置，没有则使用sync配置进行同步
            "search":{
                "type":"text",
                "operator":"eq",
                "componentName":"TextField",
                "key":"textField_m1nbexlw" # 查询项目编号
            },
            # 同步配置
            "sync":{
                "func":"sync_project", # 同步函数 用于处理未在宜搭表中存在的联合数据的同步的函数，该函数必须在views_jy_sync模块内
                "company_name":"linanzjz" # 公司名字
            },
            # 联合字段填充配置
            "fill":{
                "title_field_name":"textField_lzrzlfjr", # 要填充的联合表的字段
                # 填充关联字段相关的其他字段 源关联表单字段 -> 目标表单映射
                "form_fields":{
                    "textField_m1nbexlw": "textField_m0am6qv4", # 项目编号
                    "textField_lzrzlfjr": "textField_lzuvzaex", # 项目名称
                    "textareaField_lzxvw0ez": "textField_lzxv9z3u", # 项目地址
                },
            },

            # 反向同步配置
            "inverse_sync":{
                # 数据库字段 -> 表单字段映射 填充到数据库中的哪些字段，从宜搭的form_instance中取出
                "db_fields":{
                    "ProjectNum": "textField_m0am6qv4", # 项目编号
                }
            }
        },
        # 样品中的项目名称联合表单
        "associationFormField_lzuvjinv":{
            # 被关联表单配置信息
            "appType": 'APP_Z006W6F6CE9REPXVWPH6',
            "formType": 'receipt',
            "formUuid": 'FORM-BD41952201D4490A804B013A18E98A5CQYKA',
            # 正向同步配置
            # 查找关联的表的配置，没有则使用sync配置进行同步
            "search":{
                "db_field":"ProjectNum", # 根据数据库中的哪个字段进行查询
                "type":"text",
                "operator":"eq",
                "componentName":"TextField",
                "key":"textField_m1nbexlw" # 查询项目编号
            },
            # 同步配置
            "sync":{
                "func":"sync_project", # 同步函数 用于处理未在宜搭表中存在的联合数据的同步的函数，该函数必须在views_jy_sync模块内
                "company_name":"linanzjz" # 公司名字
            },
            # 联合字段填充配置
            "fill":{
                "title_field_name":"textField_lzrzlfjr", # 要填充的联合表的哪个字段到目标表
                # 填充关联字段相关的其他字段 源关联表单字段 -> 目标表单映射
                "form_fields":{},
            },
            # 反向同步配置 这里不需要
            "inverse_sync":{}
        }
    }

    # 跨表查询配置
    join_table_query_config = {
        "item_spec_query_config":{
            "specStorageField":"selectField_m0emrkj1", # 规格字段存储在哪里            
            "ACBR": {
                "ItemChName": "混凝土结构后锚固",
                "specField": ""
            },
            "BHCK": {
                "ItemChName": "现浇钢筋混凝土板厚",
                "specField": ""
            },
            "BWNJ": {
                "ItemChName": "保温拉伸粘结强度",
                "specField": ""
            },
            "CEMT": {
                "ItemChName": "09水泥物理性能",
                "specField": ""
            },
            "CZHZ": {
                "ItemChName": "99承重混凝土多孔砖MU15",
                "specField": ""
            },
            "GHJC": {
                "ItemChName": "05钢筋焊接接头性能(初检)",
                "specField": "da",
                "associatedParameterName":"抗拉强度",
            },
            "GHJF": {
                "ItemChName": "06钢筋焊接接头性能(复检)",
                "specField": "da",
                "associatedParameterName":"抗拉强度",         
            },
            "GJCC": {
                "ItemChName": "03钢筋原材拉伸及弯曲性能(初检)",
                "specField": "da",
                "associatedParameterName":"抗拉强度"
            },
            "GJCF": {
                "ItemChName": "04钢筋原材拉伸及弯曲性能(复检)",
                "specField": "da",
                "associatedParameterName":"抗拉强度"                
            },
            "GMJC": {
                "ItemChName": "07钢筋机械连接接头(初检)",
                "specField": "da",
                "associatedParameterName":"抗拉强度"                
            },
            "GMJF": {
                "ItemChName": "08钢筋机械连接接头(复检)",
                "specField": "da",
                "associatedParameterName":"抗拉强度"                
            },
            "GSKJ": {
                "ItemChName": "20钢管脚手架扣件",
                "specField": ""
            },
            "GTUB": {
                "ItemChName": "18钢管(初检)",
                "specField": ""
            },
            "HNHZ": {
                "ItemChName": "15混凝土普通砖",
                "specField": ""
            },
            "HNKS": {
                "ItemChName": "10混凝土抗水渗透性能",
                "specField": "pdksdj"
            },
            "HNKY": {
                "ItemChName": "01混凝土试块抗压强度",
                "specField": ""
            },
            "HNKZ": {
                "ItemChName": "24混凝土试块抗折",
                "specField": ""
            },
            "HNTZ": {
                "ItemChName": "16混凝土多孔砖",
                "specField": ""
            },
            "HTCK": {
                "ItemChName": "38回弹法检测混凝土抗压强度",
                "specField": ""
            },
            "HTML": {
                "ItemChName": "回弹模量(承载板法)",
                "specField": ""
            },
            "JZMC": {
                "ItemChName": "建筑门窗",
                "specField": ""
            },
            "KXQK": {
                "ItemChName": "94普通混凝土小型空心砌块",
                "specField": ""
            },
            "KXZF": {
                "ItemChName": "98非承重混凝土空心砖MU10",
                "specField": ""
            },
            "LMWC": {
                "ItemChName": "道路弯沉",
                "specField": ""
            },
            "MCBW": {
                "ItemChName": "门窗保温",
                "specField": ""
            },
            "MDGT": {
                "ItemChName": "灌砂法测定土的密度(国标)",
                "specField": ""
            },
            "SBPL": {
                "ItemChName": "钢筋保护层厚度",
                "specField": ""
            },
            "SIIG": {
                "ItemChName": "12石子物理性能(国标)",
                "specField": ""
            },
            "SJDK": {
                "ItemChName": "13烧结多孔砖",
                "specField": ""
            },
            "SJKX": {
                "ItemChName": "17烧结空心砖和砌块",
                "specField": ""
            },
            "SJKY": {
                "ItemChName": "02砂浆试块抗压试验",
                "specField": ""
            },
            "SJPZ": {
                "ItemChName": "14烧结普通砖",
                "specField": ""
            },
            "SOIL": {
                "ItemChName": "土壤击实",
                "specField": ""
            },
            "STON": {
                "ItemChName": "23砂浆配合比",
                "specField": ""
            },
            "SZIG": {
                "ItemChName": "11砂子物理性能(国标)",
                "specField": ""
            },
            "TGHD": {
                "ItemChName": "环刀法测定土的密度(国标)",
                "specField": ""
            },
            "THSF": {
                "ItemChName": "钻芯法检测混凝土芯样强度",
                "specField": ""
            },
            "TONO": {
                "ItemChName": "22混凝土配合比",
                "specField": ""
            },
            "XMZH": {
                "ItemChName": "饰面砖粘接强度",
                "specField": ""
            },
            "ZYHZ": {
                "ItemChName": "蒸压灰砂实心砖和实心砌块",
                "specField": ""
            },
            "ZYJQ": {
                "ItemChName": "21蒸压加气混凝土砌块",
                "specField": ""
            }
        }
    }
